// L2-005
#include <iostream>
#include <set>
#include <algorithm>
#include <cstdio>
using namespace std;

set<int> a[55];
int n;
void func(int x, int y)
{
    int s = 0;
    for (set<int>::iterator it = a[x].begin(); it != a[x].end(); it++)
    {
        if (a[y].find(*it) != a[y].end())
        {
            s++;
        }
    }
    int sum = a[x].size() + a[y].size();
    int Nt = sum - s;
    printf("%.2lf%%\n", s * 1.0 / Nt * 100);
}
int main()
{
    cin >> n;
    int t, m, k;
    for (int i = 1; i <= n; i++)
    {
        cin >> m;
        for (int j = 0; j < m; j++)
        {
            cin >> t;
            a[i].insert(t);
        }
    }
    cin >> k;
    int x, y;
    for (int i = 0; i < k; i++)
    {
        cin >> x >> y;
        func(x, y);
    }
    return 0;
}